<script>
import { mapState, mapMutations } from "vuex";
export default {
  computed: mapState(["hasLogin", "uerInfo"]),
  // methods:{
  // 	...mapMutations(['login'])
  // },
  onLaunch: function () {
    var platform = uni.getSystemInfoSync().platform;
    if (platform === "android") {
      uni.setStorageSync("device", 0);
    }
    if (platform === "ios") {
      uni.setStorageSync("device", 1);
    }
    let info = plus.push.getClientInfo();
    console.log(info);
    /* 5+  push 消息推送 ps:使用:H5+的方式监听，实现推送*/
    plus.push.addEventListener(
      "click",
      function (msg) {
        //ios端
        if (platform === "ios") {
          //离线是payload为object , 在线时本地创建的为string(本地创建通知只能传string，否则无法传递payload)
          if (typeof msg.payload == "string") {
            console.log("string");
            var paymsg = JSON.parse(msg.payload);
          } else {
            console.log("obj");
            var paymsg = msg.payload;
          }
          console.log(paymsg);
          //执行跳转判断
        }
        //安卓
        console.log(platform);
        console.log(JSON.stringify(msg));
        console.log(msg.payload);
        //这里可以写跳转业务代码
        // uni.navigateTo({
        // 	url:'pages/main/pub/message-list'
        // })
      },
      false
    );
    //监听在线消息事件
    plus.push.addEventListener(
      "receive",
      function (msg) {
        plus.push.createMessage(msg.payload.path);
        // msg.payload.content,
        //本地创建通知payload只能传string，否则无法成功传递（为null）
        // JSON.stringify(msg.payload), {
        // 	cover: false,
        // 	title: msg.title,
        // });
        // plus.ui.alert(2);
        //这里可以写跳转业务代码
        // uni.navigateTo({
        // 	url:'pages/main/pub/message-list'
        // })
        console.log("recevice:" + JSON.stringify(msg));
      },
      false
    );

    //this.jsBan()  //检测升级
    //获取Cid
    this.getCid();
    this.sendCid();
    this.autoDownNew();
  },
  onShow: function () {
    // this.getUiStyle(); //夜间模式开关
    console.log("App Show");
  },
  onUnload() {
    // 移除监听事件
    uni.$off("loginOutCode", this.callback);
  },
  onHide: function () {
    //this.getUiStyle();
    console.log("App Hide");
  },
  methods: {
    //检测更新
    autoDownNew() {
      const type = uni.getStorageSync("device");
      const device = plus.runtime.versionCode;
      console.log(device);
      console.log(type);
      this.config
        .get("/appVersion/getAppversion", {
          type: type,
        })
        .then((res) => {
          if (res.data.msg > device) {
            uni.showModal({
              title: "版本升级提示",
              content:
                "系统检测到最新版本，请前往应用商店进行更新，避免影响正常使用",
              success: function (res) {
                uni.hideToast();
                if (res.confirm) {
                  uni.redirectTo({
                    url: "/pages/login/login2",
                  });
                } else if (res.cancel) {
                }
              },
            });
          }
        });
    },
    sendCid() {
      this.config
        .post("/uni/saveCidToUser", {
          cid: uni.getStorageSync("cid"),
          ptType: uni.getStorageSync("device"),
        })
        .then((res) => {
          console.log(res);
        });
    },
    jsBan() {
      plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
        this.version = wgtinfo.versionCode;
        console.log(wgtinfo.versionCode);
      });
    },
    //获取cid
    getCid() {
      // #ifdef  APP-PLUS
      console.log("获取cid");
      var t1 = setInterval(function () {
        // console.log('定时器');
        //扩展API加载完成事
        var cid = plus.push.getClientInfo().clientid;
        if (cid && cid != null && cid != "null") {
          try {
            console.log(cid);
            uni.setStorageSync("cid", cid);
            this.cid = cid;
          } catch (e) {
            console.log("获取cid失败");
          }
          clearInterval(t1);
        }
      }, 500);
      // #endif
    },
    getUiStyle() {
      var style = plus.navigator.getUiStyle();
      this.ptcolor(style);
    },
    ptcolor(style) {
      if ("dark" == style) {
        console.log("当前为暗黑模式");
        uni.setTabBarStyle({
          backgroundColor: "#1B1C1E",
        });
        uni.setNavigationBarColor({
          frontColor: "#ffffff",
          backgroundColor: "#1B1C1E",
          animation: {
            duration: 400,
            timingFunc: "easeIn",
          },
        });
        uni.setBackgroundTextStyle({
          textStyle: "dark",
        });
        uni.setBackgroundColor({
          backgroundColor: "#1B1C1E",
          backgroundColorTop: "#1B1C1E",
          backgroundColorBottom: "#1B1C1E",
        });
      } else {
        console.log("当前为普通模式");
        uni.setTabBarStyle({
          backgroundColor: "#fff",
        });
      }
    },
  },
  // onThemeChange: function (res) {
  //   let style = res.style;
  //   if ("dark" == style) {
  //     console.log("当前为暗黑模式");
  //     uni.setTabBarStyle({
  //       backgroundColor: "#1B1C1E",
  //     });
  //     uni.setNavigationBarColor({
  //       frontColor: "#ffffff",
  //       backgroundColor: "#1B1C1E",
  //       animation: {
  //         duration: 400,
  //         timingFunc: "easeIn",
  //       },
  //     });
  //     uni.setBackgroundTextStyle({
  //       textStyle: "dark",
  //     });
  //     uni.setBackgroundColor({
  //       backgroundColor: "#1B1C1E",
  //       backgroundColorTop: "#1B1C1E",
  //       backgroundColorBottom: "#1B1C1E",
  //     });
  //   } else {
  //     console.log("当前为普通模式");
  //     uni.setTabBarStyle({
  //       backgroundColor: "#fff",
  //     });
  //   }
  // },
};
</script>
<style lang="scss">
.empty_center_icon {
  //居中显示无数据
  position: absolute;
  top: 50%;
  left: 50%; /*定位margin-left:50%的位置*/
  -webkit-transform: translate(-50%, -50%); /*Safari,Chrome*/
  -moz-transform: translate(-50%, -50%); /*IE9+*/
  transform: translate(-50%, -50%); /*使元素本身向左移动宽度的一半*/
}
/*每个页面公共css */
/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
@import "uview-ui/index.scss";
/*每个页面公共css*/
@import "/static/css/global.css";
/*引入阿里图标库*/
@import "/static/css/iconfont.css";
@import "/static/iconfont.css";
@import "/static/css/animate_min.css";

// *{
// 	background-color: #1B1C1E !important;
// 	color: #FFFFFF !important;
// }
@media (prefers-color-scheme: light) {
  //白天模式
  .uni-tabbar {
    background-color: #ffffff !important;
  }
}

@media (prefers-color-scheme: closedark) {
  //  黑暗模式
  .uni-tabbar__icon {
    background: none !important;
  }

  .uni-tabbar__bd {
    background: none !important;
  }

  .uni-tabbar {
    margin-bottom: -1px;
  }

  //滑出卡片的阴影
  .letter-box {
    box-shadow: -1px 1px 4px 0px #005765 !important;
  }

  .uni-tabbar {
    background-color: #1b1c1e !important;
  }

  .uni-tabbar-border {
    background-color: #ccc !important;
  }

  .uni-picker-view-content {
    background-color: #1b1c1e !important;
  }

  .uni-picker-view-mask {
    background-color: #1b1c1e !important;
    z-index: 0;
  }
}
</style>
